#include<bits/stdc++.h>
using namespace std;

string s[1010];

int main() {
	int n;
	cin >> n;

	getchar();

	for (int i = 1; i <= n; i++) {

		getline(cin, s[i]);

		for (int j = 0; j < s[i].size();) {
			if (s[i][j] == ' ')
				cout << s[i][j++];
			else {
				string t;
				for (int k = j; s[i][k] != ' ' && k < s[i].size(); k++)
					t += s[i][k];

				reverse(t.begin(), t.end());
				cout << t;

				j += t.size();
			}
		}
		cout << endl;
	}
	return 0;
}

